﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TangoGames.Base;
using TangoGames.Scene;
using incubation_xna3d.Scene;

namespace incubation_xna3d.Screens
{
    class Fimdejogo : Screen
    {

        IInputService input;

        SpriteBatch spriteBatch;


        Texture2D ponteiro;
        Vector2 ponteiroposition;


        Texture2D fundo;
        Texture2D voltar;
        Texture2D fim;

        public Boolean chamouvoltar = false;

        public Fimdejogo(Game game)
            : base(game)
        {


            input = (IInputService)game.Services.GetService(typeof(IInputService));
            // cria o ponteiro do mouse
            ponteiro = Game.Content.Load<Texture2D>("Textures/HUD/ponteiro");
            ponteiroposition = Vector2.Zero;


            fundo = game.Content.Load<Texture2D>("Textures/Creditos/fundo");
            voltar = game.Content.Load<Texture2D>("Textures/Creditos/voltar");
            fim = game.Content.Load<Texture2D>("Textures/Menu/fimdejogo");

        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }


        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            ponteiroposition.X = input.mouse.X;
            ponteiroposition.Y = input.mouse.Y;

            Botoes();

        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();

            spriteBatch.Draw(fundo, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(fim, new Vector2(Game.Window.ClientBounds.Width/2 - fim.Width/2, Game.Window.ClientBounds.Height/2 - 250), Color.White);
            spriteBatch.Draw(voltar, MouseOver(Localvoltar()), Color.White);

            spriteBatch.Draw(ponteiro, ponteiroposition, Color.White);
            spriteBatch.End();
        }






        private void Botoes()
        {
            if (input.MouseClick(Localvoltar()))
            {

                chamouvoltar = true;

            }
        }
        #region posição dos elementos

        public Rectangle Localvoltar()
        {
            return new Rectangle(Game.Window.ClientBounds.Width / 2 - voltar.Width / 2, Game.Window.ClientBounds.Height - 250, voltar.Width, voltar.Height);
        }


        #endregion


        #region Mouse over

        // verifica se o mouse esta sobre o botao para
        private Rectangle MouseOver(Rectangle inicial)
        {

            Rectangle destination;
            destination = new Rectangle();
            destination = inicial;

            // verifica se o mouse esta sobre o retangulo
            if (input.MouseOver(destination))
            {

                destination.X -= 2;
                destination.Y -= 2;
                destination.Width += 5;
                destination.Height += 5;


            }

            return destination;
        }
        #endregion 


    }

}
